﻿Public Class frmRetiroEfectivo 

    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            modificar.Enabled = True
            eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub

    Private Sub frmRetiroEfectivo_Load(sender As System.Object, e As System.EventArgs)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.usuarios' table. You can move, or remove it, as needed.
        Me.UsuariosTableAdapter.Fill(Me.DbFireAndIceDataSet.usuarios)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.reduccionesefectivo' table. You can move, or remove it, as needed.
        Me.ReduccionesefectivoTableAdapter.Fill(Me.DbFireAndIceDataSet.reduccionesefectivo)

        HoraTextBox.Text = TimeOfDay
        NombrepcTextBox.Text = My.Computer.Name
    End Sub

    Private Sub ReduccionesefectivoBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles ReduccionesefectivoBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.ReduccionesefectivoBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

    Private Sub eliminar_Click(sender As System.Object, e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                'deletequery
                Me.ReduccionesefectivoTableAdapter.Fill(Me.DbFireAndIceDataSet.reduccionesefectivo)
            Catch ex As Exception
                MsgBox("Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas", MsgBoxStyle.Critical, "Error")
            End Try
        End If
    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If MontosalidaTextEdit.EditValue < 0 Then
            ErrorProvider1.SetError(MontosalidaTextEdit, "Debe ingresar un monto de salida")
        Else
            ErrorProvider1.SetError(MontosalidaTextEdit, Nothing)

            ReduccionesefectivoBindingNavigatorSaveItem.PerformClick()
            MessageBox.Show("Se guardó el resgistro satisfactoriamente")
            Mostrar()
        End If
    End Sub

    Private Sub cancelar_Click(sender As System.Object, e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(MontosalidaTextEdit, Nothing)
        Mostrar()
        Me.ReduccionesefectivoTableAdapter.Fill(Me.DbFireAndIceDataSet.reduccionesefectivo)
    End Sub
End Class